package ldh.im.admin.config;

import ldh.common.spring.security.cryptogram.RsaUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class RsaService {

    @Value("${im.rsaPublicKey2}")
    private String rsaPublicKey;

    @Value("${im.rsaPrivateKey1}")
    private String rsaPrivateKey;

    public String encryptByPrivateKey(String msg) throws Exception {
        return RsaUtil.encryptByPrivateKey(msg, rsaPrivateKey);
    }

    public String decryptByPublicKey(String encodeMsg) throws Exception {
        return RsaUtil.decryptByPublicKey(encodeMsg, rsaPublicKey);
    }

    public String encryptByPublicKey(String msg) throws Exception {
        return RsaUtil.encryptByPublicKey(msg, rsaPublicKey);
    }

    public String decryptByPrivateKey(String encodeMsg) throws Exception {
        return RsaUtil.decryptByPrivateKey(encodeMsg, rsaPrivateKey);
    }
}
